package com.mikey.emoji.configer;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import java.time.Duration;

@Configuration
@EnableCaching
public class CachingConfig {
@Bean
    public RedisCacheManager redisCacheManager(RedisConnectionFactory redisCacheConnectionFactory){
    RedisCacheWriter redisCacheWriter=RedisCacheWriter.lockingRedisCacheWriter(redisCacheConnectionFactory);
    RedisCacheConfiguration redisCacheConfiguration=RedisCacheConfiguration.defaultCacheConfig();
    redisCacheConfiguration.entryTtl(Duration.ofSeconds(30));
    RedisCacheManager redisCacheManager=new RedisCacheManager(redisCacheWriter,redisCacheConfiguration);
    return redisCacheManager;
}
}
